package com.ivr.cm.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.IListWhiteDao;
import com.ivr.cm.vo.ListWhiteVo;

/**
 * 白名单数据实现
 * @author liugeng
 * @date 2015-12-15
 * @version 1.0
 */
public class ListWhiteDaoImpl extends JdbcDaoSupport implements IListWhiteDao {
	
	/**获得白名单列表*/
	@SuppressWarnings("unchecked")
	@Override
	public List<ListWhiteVo> getListWhiteList() {
		String sql = "select id, mobile, sp_code from tb_ivr_list_white where status = 1";
		logger.info(String.format("获得白名单列表[%s]", sql));
		List<ListWhiteVo> listWhiteVoList = this.getJdbcTemplate().query(sql,rowMapper);
		if(listWhiteVoList != null && listWhiteVoList.size() > 0){
			return listWhiteVoList;
		}
		return null;
	}
	
	private ParameterizedRowMapper<ListWhiteVo> rowMapper = new ParameterizedRowMapper<ListWhiteVo>() {
		@Override
		public ListWhiteVo mapRow(ResultSet rs, int rowNum) throws SQLException {
			ListWhiteVo listWhiteVo = new ListWhiteVo();
			listWhiteVo.setId(rs.getInt("id"));
			listWhiteVo.setMobile(rs.getString("mobile"));
			listWhiteVo.setSp_code(rs.getString("sp_code"));
			return listWhiteVo;
		}
	};
}
